class CatalogController < ApplicationController
  def index
    @books = Book.find_books_available
  end

  def list_books
    @book = Book.new(params[:book])
    session[:books] = Book.find(:all,
                                :conditions => ["title LIKE ? AND author LIKE ? AND
                                                 publisher LIKE ? AND category LIKE ?",
                                                "%#{@book.title}%", "%#{@book.author}%",
                                                "%#{@book.publisher}%", "%#{@book.category}%" ],
                                :order => :title)
    if session[:books].length == 0
      flash[:notice] = 'Nenhum livro encontrado. Por favor, realize a pesquisa novamente.'
      redirect_to :controller => 'catalog', :action => :index
    end
  end

  def show
    @book = Book.find(params[:id])

    session[:book] = Book.find(@book.id)
    session[:comments] = Comment.find_all_by_book_id(@book.id)
    session[:rentals] = Rental.find_all_by_book_id(@book.id)

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @book }
    end
  end

protected

  def authorize
  end
end
